package org.news.web.utils;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.common.Term;

import java.util.ArrayList;
import java.util.List;

public class KeywordExtractorUtils {

    public static List<String> extractKeywords(String news) {
        List<String> keywords = new ArrayList<>();
        List<Term> termList = HanLP.segment(news);
        for (Term term : termList) {
            // 仅保留名词
            if (term.nature.startsWith("n")) {
                keywords.add(term.word);
            }
        }
        return keywords;
    }

}
